﻿/**************************************************************************************************\
++++++++++++++++++++++++++++++ ARKADIUM INTELLECTUAL PROPERTY TERMS ++++++++++++++++++++++++++++++
The Software is protected by US copyright laws and international treaties. Licensee must treat the 
Software like any other copyrighted material – for example a book. Licensee acknowledges that 
Arkadium owns the Software and that nothing set forth herein conveys to Licensee any ownership in 
or to the Software, including without any Derivative Works of the Software.  
++++++++++++++++++++++++++++++ ARKADIUM INTELLECTUAL PROPERTY TERMS ++++++++++++++++++++++++++++++

AUTHOR: Tom R

PURPOSE: TODO.
\**************************************************************************************************/
import game_speedGrabber.DataManager

class game_speedGrabber.TimerClass extends MovieClip
{
	private var _sdtTimer:TextField;
	private var _nTimer:Number;
	private var _nOldTime:Number;
	private var _bTimerOn:Boolean;
	private var _nTickTime:Number;
	private var _nStartingTime:Number;
	private var _bWarned:Boolean;
	
	
	private function TimerClass()
	{
		onInitialize()
	}
	
	public function onInitialize( )
	{
		this.stop();
		_bTimerOn = false;
		_bWarned = false;
	}
	
	public function setTime(nTimer:Number){
		_nTimer = nTimer;
	}
	
	public function getTime(){
		return(_nTimer);
	}
	
	public function startTimer(){
		_nOldTime = getTimer()/1000;
		_bTimerOn = true;
	}
	
	public function stopTimer(){
		_bTimerOn = false;
	}
	
	public function startNewCountDown(nTimer:Number){
		clearTimer();
		_nStartingTime = nTimer;
		setTime(nTimer);
		
		_nOldTime = getTimer()/1000;
		_bTimerOn = true;
		onEnterFrame = countDown;
	}
	
	public function countDown(){
		//here we are getting the time based on the system clock
		//it is also possible to include here a frame based timer system
		var nGetTimer:Number = getTimer()/1000;
		
		if(_bTimerOn == true){
			_nTimer -= (nGetTimer - _nOldTime);
			if(_nTimer <= 0){
				_nTimer = 0;
				_bTimerOn = false;
				_parent.timeRanOut();
			}
			
		}
		_nOldTime = nGetTimer
		
		//This is code designed for handling a 100 frame visual timer.  
		this.gotoAndStop(100-Math.floor(100*(_nTimer/_nStartingTime)));
		
		
		var nMinutes:Number = Math.floor(_nTimer / 60);
   	 	var nSeconds:Number = Math.floor(_nTimer%60);
		
    	if (nSeconds > 9)
    	{
			_sdtTimer.text = String(nMinutes) + " : " + String(nSeconds);
    	}
   	 	else
    	{
        	_sdtTimer.text = String(nMinutes) + " : " + ("0" + String(nSeconds));
    	} // end else if
	
	}
	
	public function startNewCountUp(nTimer:Number){
		clearTimer();
		_nStartingTime = nTimer;
		setTime(nTimer);
		
		_nOldTime = getTimer()/1000;
		onEnterFrame = countUp;
		_bTimerOn = true;
	}
	
	public function countUp(){
		//here we are getting the time based on the system clock
		//it is also possible to include here a frame based timer system
		var nGetTimer:Number = getTimer()/1000;
		
		if(_bTimerOn == true){
			_nTimer += (nGetTimer - _nOldTime);
		}
		_nOldTime = nGetTimer

		_sdtTimer.text = String(_nTimer)
	}
	
	public function clearTimer(){
		onEnterFrame = null
	}
}